package com.webex.ta.hydra.core.macro;

import com.webex.ta.hydra.core.*;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Vector;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-14
 * Time: 17:04:13
 */
public class LoadMacro extends AbstractAction {
    private static ParamDescriptor[] desc = new ParamDescriptor[1];
    static {
        desc[0] = new ParamDescriptor("absolute or relative path to macro definition file(.hym)");
    }

    public ParamDescriptor[] getParamDescriptors(Command cmd) {
        return desc;
    }

    public void execute(TestResult result, String... args) throws Exception {
        InputStream istream = new FileInputStream(FileService.getInstance().getFile(args[0]));
        Vector<MacroDefinition> defs = MacroSerializer.loadMacroDefinitions(istream);
        for (MacroDefinition def : defs) {
            MacroRegistry.getInstance().register(def);
        }
    }


}
